package no18.javaio;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;

public class InputStreamTest {

	public static void main(String[] args) {
		InputStream in = System.in;
		int iRead;
		byte[] bRead = new byte[3];// 缓冲数组
		ByteArrayOutputStream bos = new ByteArrayOutputStream();
		try {
			System.out.println("please input");
			System.out.println();
			while ((iRead = in.read(bRead)) != -1) {
				// in.read(bRead) = in.read(bRead,0,bRead.length)
				// bos.write(iRead);
				// 不像上面这样写，是因为它的默认实现是bos.write(bRead,0,bRead.length);
				// 数组未必被全部填充，这样很可能出现空字节
				bos.write(bRead, 0, iRead);// 读出byte数组中实际的字节数
			}
			System.out.println(new String(bos.toByteArray()));
		} catch (IOException e) {
		}
	}
}
